﻿Imports KanBan.Pgd.Infrastructure.Exceptions

Namespace Helpers

    Public Class FormHelper

        Public Shared Sub ShowError(ByVal errorList As IList(Of ApplicationError))
            Dim errorDialog As New MessageDialog(MessageDialog.MessageDialogType.ErrorMessage, errorList)
            errorDialog.ShowDialog()
        End Sub

        Public Shared Sub ShowAsChildForm(ByVal parentForm As Form, ByVal childForm As Form)

            Dim form = parentForm.OwnedForms.Where(Function(f) f.Name = childForm.Name).SingleOrDefault()
            If (form IsNot Nothing) Then
                form.Focus()
            Else
                parentForm.AddOwnedForm(childForm)
                childForm.Show()
            End If

        End Sub

        Public Shared Function TrySetFocusOnChildForm(ByVal parentForm As Form, ByVal formName As String) As Boolean
            Dim form = parentForm.OwnedForms.Where(Function(f) f.Name = formName).SingleOrDefault()
            If (form IsNot Nothing) Then
                form.Focus()
                Return True
            End If

            Return False

        End Function

    End Class

End Namespace
